using System;
using System.DHTML;
using Sys;
using Sys.UI;

using JQuerySharp;
using VietPublisher.Scripts.Resources;

static public class SC_Common
{
    static public string DefaultDomainName = "SBusWeba.co.kr";
    static public string BasePath = "/";
    public static string GuidEmpty = "00000000-0000-0000-0000-000000000000";

    #region Multi-Tab

    public static string SelectedTabName = "";
    public static void OnClickTab(string tabName)
    {
        SelectedTabName = tabName;

        TableElement[] parent = (TableElement[])(object)JQueryFactory.JQuery("#tabTable");
        TableElement tableParent = (TableElement)parent[0];
        DOMElement row = (DOMElement)tableParent.Rows[0];

        for (int i = 0; i < row.ChildNodes.Length; i++)
        {

            DivElement div = null;
            if (row.ChildNodes[i].ID != null)
            {
                div = (DivElement)Document.GetElementById(row.ChildNodes[i].ID.Substr(2));
            }
            if (div != null)
            {
                div.Style.Display = "none";
                row.ChildNodes[i].Style.BackgroundImage = row.ChildNodes[i].Style.BackgroundImage.Replace("tab_bg2.jpg", "tab_bg1.jpg");
            }

            if (row.ChildNodes[i].ID == "bt" + tabName)
            {
                row.ChildNodes[i].Style.BackgroundImage = row.ChildNodes[i].Style.BackgroundImage.Replace("tab_bg1.jpg", "tab_bg2.jpg");

                DivElement divSelected = (DivElement)Document.GetElementById(tabName);
                divSelected.Style.Display = "block";

            }
        }

    }

    #endregion

    #region Grid Common

    public static void HideFooter(string gridId)
    {
        DOMElement grid = Document.GetElementById(gridId);
        //grid.GetElementsByTagName()
        if (grid != null && grid.Children.Length == 3)
        {
            grid.Children[2].Style.Display = "none";
        }
    }

    #endregion

    /// <summary>

    /// Check file exist and set
    /// </summary>
    /// <param name="img"></param>
    /// <param name="fileId"></param>
    static public void SetImgSrc(ImageElement img, string fileId, string defaultPath)
    {
        img.Src = defaultPath;

        string url = "/FileMan/CheckFileExist?fileId=" + fileId;
        jQuery.GetJSON(url, new Dictionary(), (Function)(object)new GenericOneArgDelegate(delegate(object data)
        {
            bool exists = (bool)Script.Literal("data.Exists");
            if (exists)
            {
                img.Src = "/Handlers/ImageHandler.ashx?fileId=" + fileId;
            }
        }));

    }

    #region FileDownload Poup

    public static void OpenFileDownload(int groupId)
    {
        string href = SC_Common.BasePath + "/Handlers/ImageHandler.ashx?groupid=" + groupId.ToString();
        Utils.OpenWinCenter("FileDown", href, 100, 100);
    }

    #endregion
}